<template>
	<div>
		<el-form :model="formInline" label-width="120px">
			<el-form-item label="患者就诊卡ID:" prop="idnumber" required="">
				<el-input v-model="formInline.idnumber" placeholder="患者就诊卡ID" style="width:300px ;"></el-input>
				<el-button type="primary" @click="getdiagnosis()">显示诊断信息</el-button>
				</el-input>
			</el-form-item>
			<el-form-item label="患者姓名:" prop="name" required="">
				<el-input v-model="formInline.name" placeholder="患者姓名" style="width:300px ;"></el-input>
			</el-form-item>
			<el-form-item label="患者性别:" prop="sex" required="">
				<el-input v-model="formInline.sex" placeholder="患者性别" style="width:300px ;"></el-input>
			</el-form-item>
			<el-form-item label="患者年龄:" prop="age" required="" required="">
				<el-input v-model="formInline.age" placeholder="患者年龄" style="width:300px ;"></el-input>
			</el-form-item>
			<el-form-item label="患者就诊日期:" prop="day" required="">
				<el-input v-model="formInline.day" placeholder="患者就诊日期" style="width:300px ;"></el-input>
			</el-form-item>
			<el-form-item label="患者诊断信息:" prop="result" required="">
				<el-input v-model="formInline.result" placeholder="患者诊断信息" style="width:300px ;"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="getptest()">显示化验信息</el-button>
			</el-form-item>
			<el-divider></el-divider>
			<el-form-item>
				<el-button type="primary" @click="dialogFormVisible = true">添加化验项目</el-button>
				<el-button type="primary" style="margin-left: 50px;" @click="dialogVisible=true;putptest()">打印化验信息
				</el-button>
			</el-form-item>
			<el-dialog title="选择化验项目" :visible.sync="dialogFormVisible">
				<el-form-item property="project" label="">
					<el-col :span="5" class="addtest">
						<p>化验项目</p>
					</el-col>
					<el-col :span="9" class="addtest">
						<el-select v-model="formInline.project" placeholder="请选择">
							<el-option label="尿常规" value="尿常规"></el-option>
							<el-option label="乙肝检查" value="乙肝检查"></el-option>
							<el-option label="血型检查" value="血型检查"></el-option>
							<el-option label="甲肝检查" value="甲肝检查"></el-option>
							<el-option label="抗核抗体十项" value="抗核抗体十项"></el-option>
							<el-option label="过敏源检测" value="过敏源检测"></el-option>
						</el-select>
					</el-col>
					<el-col :span="1" class="addtest">
						<el-button type="primary" @click="gettest()">显示</el-button>
					</el-col>
				</el-form-item>
				<el-row>
					<el-form-item label="" prop="money">
						<el-col :span="5" class="addtest">
							<p>费用</p>
						</el-col>
						<el-col :span="9" class="addtest">
							<el-input v-model="formInline.money"></el-input>
						</el-col>
					</el-form-item>
				</el-row>
				<el-row>
					<el-form-item label="">
						<el-col :span="5" class="addtest">
							<p>科室</p>
						</el-col>
						<el-col :span="9" class="addtest">
							<el-input v-model="formInline.room"></el-input>
						</el-col>
						<el-col :span="1" class="addtest">
						</el-col>
					</el-form-item>
				</el-row>
				<div slot="footer" class="dialog-footer">
					<el-button type="primary" @click="submitForm">添加</el-button>
					<el-button @click="dialogFormVisible = false">取 消</el-button>
					<el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
				</div>
			</el-dialog>
			<el-dialog title="检查信息" :visible.sync="dialogVisible">
				<el-table :data="gData">
					<el-table-column prop="name" label="患者姓名" width="140">
					</el-table-column>
					<el-table-column prop="sex" label="性别" width="140">
					</el-table-column>
					<el-table-column prop="age" label="年龄" width="140">
					</el-table-column>
					<el-table-column prop="project" label="项目" width="140">
					</el-table-column>
					<el-table-column prop="room" label="执行科室" width="160">
					</el-table-column>
					<el-table-column prop="money" label="价格" width="140">
					</el-table-column>
					<el-table-column prop="state" label="状态" width="140">
					</el-table-column>
				</el-table>
				<h1>&emsp;</h1>
				
				<el-button type="primary" @click="dialogVisible = false">确定</el-button>
			</el-dialog>
			<el-dialog title="化验信息" :visible.sync="dialogVisible">
				<el-table :data="gridData">
					<el-table-column prop="name" label="患者姓名" width="140">
					</el-table-column>
					<el-table-column prop="sex" label="性别" width="140">
					</el-table-column>
					<el-table-column prop="age" label="年龄" width="140">
					</el-table-column>
					<el-table-column prop="project" label="项目" width="140">
					</el-table-column>
					<el-table-column prop="room" label="执行科室" width="160">
					</el-table-column>
					<el-table-column prop="money" label="价格" width="140">
					</el-table-column>
					<el-table-column prop="state" label="状态" width="140">
					</el-table-column>
				</el-table>
				<h1>&emsp;</h1>
				<el-button type="primary" @click="dialogVisible = false">确定</el-button>
			</el-dialog>
		</el-form>
		<el-divider></el-divider>
		<el-table :data="testtable" style="width: 100%" max-height="250">
			<el-table-column prop="num" label="流水号" width="220">
			</el-table-column>
			<el-table-column prop="project" label="项目" width="220">
			</el-table-column>
			<el-table-column prop="room" label="执行科室" width="220">
			</el-table-column>
			<el-table-column prop="money" label="价格" width="220">
			</el-table-column>
			<el-table-column prop="state" label="状态" width="220">
			</el-table-column>
			<el-table-column fixed="right" label="操作" width="150">
				<template slot-scope="scope">
					<el-button @click.native.prevent="deleteRow(scope.$index, testtable)" type="primary" size="small">
						移除
					</el-button>
				</template>
			</el-table-column>
		</el-table>





	</div>
</template>

<script>
	import {
		showMsgTitle
	} from '@/utils/api'
	import {
		showMsgConfirm
	} from '@/utils/api'
	import {
		getRequest
	} from '@/utils/api'
	import {
		postRequest
	} from '@/utils/api'
	import {
		uploadFileRequest
	} from '@/utils/api'
	import {
		putRequest
	} from '@/utils/api'
	import {
		deleteRequest
	} from '@/utils/api'
	import {
		showConstants
	} from '@/utils/api'
	export default {
		data() {
			return {
				testData: [],
				project: false,
				formInline: {
					idnumber: '',
					project: '',
					money:'',
					room: '',
					name: ',',
					age: '',
					sex: '',
					name: '',
					result: ''
				},
				getcheckresult: false,
				dialogTableVisible: false,
				dialogFormVisible: false,
				dialogVisible: false,
				formLabelWidth: '120px',
			    gData :[],
				form1: [],
				testtable: [],
				getcheckresult: false,
				dialogTableVisible: false,
				dialogFormVisible: false,
				dialogVisible: false,
				formLabelWidth: '120px',
				form1: [],
				testtable: [],
				gridData: [],
				checkresult: {}
			}
		},
		methods: {
			deleteRow(index, rows) {
				console.log(rows)
				postRequest('/delptest?num=' + this.testtable[index].num);
				rows.splice(index, 1);
			},
			getdiagnosis() {
				this.$axios.get('http://localhost:8081/idconfirm?idnumber=' + this.formInline.idnumber).then((result) => {
					console.log(result.data);
					this.formInline = result.data[0];
				}).catch((err) => {
					console.log(error);
				});
			},
			putptest() {
				this.$axios.get('http://localhost:8081/idptest?idnumber=' + this.formInline.idnumber).then((result) => {
					console.log(result.data);
					this.gridData = result.data
				}).catch((err) => {
					console.log(error);
				});
			},

			getptest() {
				this.$axios.get('http://localhost:8081/idptest?idnumber=' + this.formInline.idnumber).then((result) => {
					console.log(result.data);
					this.testtable = result.data
				}).catch((err) => {
					console.log(error);

				});
			},
			gettest() {
				this.$axios.get('http://localhost:8081/mestest?name=' + this.formInline.project).then((result) => {
					console.log(result.data);
					this.formInline.money = result.data[0].money;
					//this.formInline.project = result.data[0].name;
					// console.log(result.data);
					// this.form = result.data;
				}).catch((err) => {
					console.log(error);
				});
				this.$axios.get('http://localhost:8081/mestest?name=' + this.formInline.project).then((result) => {
					console.log(result.data);
					this.formInline.room = result.data[0].room;
					//this.formInline.project = result.data[0].name;
					// console.log(result.data);
					// this.form = result.data;
				}).catch((err) => {
					console.log(error);
				});
			},
			submitForm(formName) {
				postRequest('/addptest', this.formInline).then(resp => {

					alert("开具化验成功！");
				}).catch((err) => {
					alert("开具化验失败，请重新开具！");
				});
			},
		}
	}
</script>



<style>
	.addtest.el-col {
		background-color: #FFFFFF;
	}
</style>
